exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
    /**
     * 获取所有区域全部
     *
     * @returns
     */
    getAreaDataAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const PartsService = _this.service('basesource/PartsService');
            const res = yield PartsService.getAreaData();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this.json(aj);
        })();
    }
    /**
     * 获取所有部件分类列表
     */
    getPGDataAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const PartsService = _this2.service('basesource/PartsService');
            const res = yield PartsService.getPGData();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this2.json(aj);
        })();
    }

    /**
     * 获取所有部件分类列表
     */
    getEVDataAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const PartsService = _this3.service('basesource/PartsService');
            const res = yield PartsService.getEVData();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this3.json(aj);
        })();
    }
    /**
     * 分页查询部件列表
     */
    getPartsListAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this4.post();
            console.log('62', data);
            const PartsService = _this4.service('basesource/PartsService');
            const res = yield PartsService.getPartsLists(data);
            if (res.error) {
                aj.success = false;
                aj.msg = '查询部件列表失败！';
            } else {
                aj.result = res;
            }
            return _this4.json(aj);
        })();
    }

    /**
     * 新增或更新部件
     */
    doAddOrUpdatePartAction() {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            const file = _this5.file('image');
            const aj = think.ajaxJson();
            const data = _this5.post();
            if (file) {
                // 保存图片
                // const pathObj = await this.renameFile(file);
                const pathObj = yield _this5.saveFile(file);
                if (pathObj) {
                    data.pic_path = pathObj.filePathStatic;
                    const PartsService = _this5.service('basesource/PartsService');
                    const res2 = yield PartsService.doAddOrUpdate(_this5.post('userid'), data);
                    return _this5.json(res2);
                } else {
                    aj.success = false;
                    aj.msg = '图片保存失败';
                    return _this5.json(aj);
                }
            } else {
                aj.success = false;
                aj.msg = '图片保存失败';
                return _this5.json(aj);
            }
        })();
    }

    /**
     * 删除部件
     */
    delPartAction() {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = {
                id: _this6.post('id')
            };
            _this6.delFile(_this6.post('pic_path')); // 未考虑无图
            // if (delPic) {
            const PartsService = _this6.service('cms/PartsService');
            const res = yield PartsService.delParts(data);
            if (res.error) {
                aj.msg = '部件信息删除失败';
                aj.success = false;
            }
            // } else {
            //     aj.msg = '图片删除失败';
            //     aj.success = false;
            // }

            return _this6.json(aj);
        })();
    }

    /**
     * 查询所有部件信息
     *
     * @returns
     */
    queryPartsAllListAction() {
        var _this7 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this7.service('cms/PartsService');
            const res = yield CmsService.getPartsAllList();
            return _this7.json(res);
        })();
    }

    /**
     * 查询部件与部件分类信息
     *
     * @returns
     */
    queryPartsAndGroupInfoAction() {
        var _this8 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this8.get('page,pageSize');
            const CmsService = _this8.service('cms/PartsService');
            const res = yield CmsService.getPartsAndGroupInfo(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this8.json(aj);
        })();
    }

    queryPartCountAction() {
        var _this9 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const CmsService = _this9.service('cms/PartsService');
            const res = yield CmsService.getPartCount();
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this9.json(aj);
        })();
    }

    queryBadPartsAndGroupInfoAction() {
        var _this10 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this10.post();
            const CmsService = _this10.service('cms/PartsService');
            const res = yield CmsService.getBadPartsAndGroupInfo(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this10.json(aj);
        })();
    }

    /**
     * 查询部件
     */
    queryPartsAction() {
        var _this11 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this11.service('cms/PartsService');
            const postData = {
                id: _this11.post('id')
            };
            const res = yield CmsService.getParts(postData);
            return _this11.json(res);
        })();
    }

    queryPartOneInfoAction() {
        var _this12 = this;

        return _asyncToGenerator(function* () {
            const CmsService = _this12.service('cms/PartsService');
            const postData = {
                id: _this12.post('id')
            };
            const res = yield CmsService.getPartOneInfo(postData);
            return _this12.json(res);
        })();
    }

    /**
     * 查询损害的部件
     * @returns {Response | *}
     * @private
     */
    queryBadPartsAction() {
        var _this13 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const data = _this13.post('ObjState');
            const CmsService = _this13.service('cms/PartsService');
            const res = yield CmsService.getBadParts(data);
            console.log('95', res);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this13.json(aj);
        })();
    }

    /**
     * 添加所属单元格id:BGID
     */

    addPartBGIDAction() {
        var _this14 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const BGIDService = _this14.service('cms/PartsService');
            const res = yield BGIDService.partsBGID(_this14.post());
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '保存失败';
            }

            return _this14.json(aj);
        })();
    }

    /**
     * 查询字典表数据来源
     * @returns {Response | *}
     * @private
     */

    dataSourceAction() {
        var _this15 = this;

        return _asyncToGenerator(function* () {
            const aj = think.ajaxJson();
            const dataSourceService = _this15.service('basesource/partsService');
            const data = _this15.get();
            const result = yield dataSourceService.dataSource(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this15.json(aj);
        })();
    }
};